//
//  PointerView.m
//  CircleAnimation
//
//  Created by fujin on 15/10/21.
//  Copyright © 2015年 fujin. All rights reserved.
//

#import "PointerView.h"
#import "SanView.h"
@interface PointerView ()<CAAnimationDelegate>
@property (nonatomic, assign) CGFloat startAngle;
@property (nonatomic, strong) SanView *sanView;
@end
@implementation PointerView
-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
self.backgroundColor = [UIColor clearColor];
      
    }
    return self;
}



-(void)updatePointer:(NSInteger)percent withAnimationTime:(CGFloat)animationTime{
    CGFloat angle = percent/10000.0 * (M_PI*2);
    
    //旋转动画
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    animation.duration = animationTime;
    animation.timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseInEaseOut];
    animation.autoreverses = NO;
    animation.fromValue = [NSNumber numberWithFloat:self.startAngle];
    animation.toValue = [NSNumber numberWithFloat:angle];
    animation.delegate = self;
    [animation setValue:[NSNumber numberWithFloat:angle] forKey:@"angle"];
    [_sanView.layer addAnimation:animation forKey:@"rotationAnimation"];
}
-(void)clear{
    self.transform = CGAffineTransformMakeRotation(0);
    self.startAngle = 0.0;
}
@end
